#!/bin/bash

#终端执行./build.sh arm_app all 

export DEVTYPE XH03A
DEVTYPE="$1"
echo "DEVTYPE is $DEVTYPE"

echo "----arm app compile start----"
current_date=$(date +%Y-%m-%d-%H-%M-%S) # 获取当前日期，格式为YYYY-MM-DD-HH-MM-SS
echo -e "\033[1;41m compile date $current_date \033[0m"

current_path=$(pwd)
echo "$current_path"
cd ..
source_dir=$(pwd)
echo "$source_dir"

var=1
case $var in
    1)
    echo "case choose 1"
    ;;
    2)
    echo "case choose 2"
    ;;
esac

if [ "$2" = "all" ]
then
    #编译静态库
    cd lib_app/liba_app
    rm -f libfunc.a
    make
    if [ -f libfunc.a ] 
    then
        echo "libfunc a compile success !!!"
        cp libfunc.a $source_dir/arm_app/applib/
        cp libfunc.h $source_dir/arm_app/include/
    else
        echo "libfunc a compile failed !!!"
        exit
    fi

    #编译动态库
    cd $source_dir
    cd lib_app/libso_app
    rm -f libfuncso.so
    make
    if [ -f libfuncso.so ] 
    then
        echo "libfunc so compile success !!!"
        cp libfuncso.so $source_dir/arm_app/applib/
        cp libfuncso.h $source_dir/arm_app/include/
    else
        echo "libfunc so compile failed !!!"
        exit
    fi

    #编译数据库
    cd $source_dir
    cd lib_app/sqlite-amalgamation-3400100
    rm -f libsqlite3.a
    make
    if [ -f libsqlite3.a ] 
    then
        echo "sqlite3 compile success !!!"
        cp libsqlite3.a $source_dir/arm_app/applib/
        cp sqlite3.h $source_dir/arm_app/include/
        cp sqlite3ext.h $source_dir/arm_app/include/
    else
        echo "sqlite3 compile failed !!!"
        exit
    fi

else
    echo "only compile app !!!"
fi

#编译应用程序
cd $current_path

make clean

make

cd release

if [ -f arm_app ] 
then
    echo "arm app compile success !!!"
else
    echo "arm app compile failed !!!"
fi   